package question

import (
	"strconv"
	"strings"
)

func CompareVersion(version1 string, version2 string) int {
	slice1 := strings.Split(version1, ".")
	slice2 := strings.Split(version2, ".")

	len1 := len(slice1)
	len2 := len(slice2)

	length := 0
	if len1 > len2 {
		length = len1
	} else {
		length = len2
	}
	for i := 0; i < length; i++ {
		revision1 := 0
		revision2 := 0

		if i < len1 {
			revision1, _ = strconv.Atoi(slice1[i])
		}
		if i < len2 {
			revision2, _ = strconv.Atoi(slice2[i])
		}
		if revision1 > revision2 {
			return 1
		} else if revision1 < revision2 {
			return -1
		}
	}
	return 0
}
